﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Luka;

/// <summary>
/// 服务分组添加-让代码更加整洁规范
/// </summary>
[NotScanned]
public static class BaseTidy
{
    /// <summary>
    /// 注入基础配置
    /// </summary>
    /// <returns>IMvcBuilder</returns>
    public static IMvcBuilder Tidy(this IMvcBuilder builder, Action<IMvcBuilder>? action = default)
    {
        action?.Invoke(builder);
        return builder;
    }

    /// <summary>
    /// 注入基础配置
    /// </summary>
    /// <returns>IWebHostBuilder</returns>
    public static IConfigurationBuilder Tidy(this IConfigurationBuilder builder, Action<IConfigurationBuilder>? action = default)
    {
        action?.Invoke(builder);
        return builder;
    }

    /// <summary>
    /// 注入基础配置
    /// </summary>
    /// <returns>IServiceCollection</returns>
    public static IServiceCollection Tidy(this IServiceCollection services, Action<IServiceCollection>? action = default)
    {
        //执行自定义组件
        action?.Invoke(services);
        return services;
    }

    /// <summary>
    /// 注入基础配置
    /// </summary>
    /// <returns>IWebHostBuilder</returns>
    public static IWebHostBuilder Tidy(this IWebHostBuilder builder, Action<IWebHostBuilder>? action = default)
    {
        action?.Invoke(builder);
        return builder;
    }

    /// <summary>
    /// 注入基础配置
    /// </summary>
    /// <returns>IHostBuilder</returns>
    public static IHostBuilder Tidy(this IHostBuilder builder, Action<IHostBuilder>? action = default)
    {
        action?.Invoke(builder);
        return builder;
    }

    /// <summary>
    /// 添加中间件
    /// </summary>
    /// <returns>WebApplication</returns>
    public static WebApplication Tidy(this WebApplication app, Action<IApplicationBuilder>? action = default)
    {
        //自定义组件
        action?.Invoke(app);
        return app;
    }
}